<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>



    <script>
        //将延迟函数封装成promise对象
        function Await(milliSecondes) {
            return new Promise(function(resolve, reject) {
                var j = 1;
                setTimeout(function() {
                    resolve("延迟函数执行成功,延迟了" + milliSecondes + "毫秒")
                }, milliSecondes * j);
                j++;
            })
        }

        function addLoadEvent(func) {
            let oldonload = window.onload;
            if (typeof window.onload != 'function') {
                window.onload = func;
            } else {
                oldonload();
                func();
            }
        }



        function saveItem(nameSpace, key, value) {
            let storage = window.localStorage.getItem(nameSpace);
            if (!storage) {
                storage = {};
            } else {
                storage = JSON.parse(storage);
            }
            storage[key] = value;
            window.localStorage.setItem(nameSpace, JSON.stringify(storage));
        }
        saveItem('kang', 'kk', 'ss')
        let k = window.localStorage.getItem("kang");
        console.log(k)

        function loadItem(key, def) {
            let storage = window.localStorage.getItem(nameSpace);
            if (!storage) {
                return def;
            }
            storage = JSON.parse(storage);
            let result = storage[key];
            return result || def;
        }
    </script>


</body>

</html>